package com.cjl.net.volley;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.cjl.net.Config;
import com.cjl.net.Request;
import com.cjl.net.Response;

public class VolleyClient implements Request {

    @Override
    public void request(Context context, Config config, String url, Response response) {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        StringRequest stringRequest = new StringRequest(
                config.getMethod().equals("GET") ? com.android.volley.Request.Method.GET : com.android.volley.Request.Method.POST,
                url,
                result -> {
                    response.success(result);
                }, error -> {
                    response.fail(error);
                });
        requestQueue.add(stringRequest);
    }
}
